<!DOCTYPE html>
<html>
  <head>
    <title>编辑枚举值</title>
     <base target=_self /> 
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    
    <link href="../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
     <link href="../../Comm/Style/Table0.css" rel="stylesheet" type="text/css" />
    <link href="../../Comm/Style/Tabs.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" language="javascript" >
        $(function () {
            
            var fk_mapdata = GetQueryString("FK_MapData");
            var KeyOfEn = GetQueryString("KeyOfEn");
            var idx = GetQueryString("IDX");
            var enumkey = GetQueryString("EnumKey");
            var captionHtml = "";
           
            if (enumkey == null){
            	captionHtml = "<a href='FieldTypeList.htm?DoType=AddF&FK_MapData=" + fk_mapdata + "&IDX=" + idx + "'><img src='../../../WF/Img/Btn/Back.gif'>&nbsp;返回</a> - <a href='Do.htm?DoType=AddSysEnum&FK_MapData=" + fk_mapdata + "&IDX=" + idx + "'>枚举字段</a> - 新建";
            }
            else{
            	if(fk_mapdata != null){
            		//$("#Btn_SaveAndAddFrm").attr("disabled","true");
            		//$("#Btn_SaveAndAddFrm").attr("style","background-color: gray;");
	            }
            	captionHtml = "<a href='FieldTypeList.htm?DoType=AddF&FK_MapData=" + fk_mapdata + "&IDX=" + idx + "'><img src='../../../WF/Img/Btn/Back.gif'>&nbsp;返回</a> - <a href='Do.htm?DoType=AddSysEnum&FK_MapData=" + fk_mapdata + "&IDX=" + idx + "'>枚举字段</a> - 编辑";
            	$("#TB_No").val(enumkey);
            	$("#TB_No").attr("readonly","true");
            	$("#TB_No").attr("class","TBReadonly");
            	
            }
            $("#caption").html(captionHtml);
    
            $.ajax({
                type: 'post',
                async: true,
                url: Handler + "?DoType=SysEnum_Init&EnumKey="+enumkey+"&FK_MapData=" + fk_mapdata + "&KeyOfEn=" +  KeyOfEn + "&m=" + Math.random(),
                dataType: 'html',
                success: function (json) {
                    if (json.indexOf('err@') == 0) {
                        alert(json);
                        return;
                    }

                    json = JSON.parse(json);
                    var SysEnums = json['Sys_Enum'];
                    var SysEnumMain = json['Sys_EnumMain'];
                    if (SysEnumMain != null)
    				{
                    	$("#TB_Name").val(SysEnumMain[0].Name);
    				}
                    var SysEnumHtml ="";
                    var idxNum = 0;
       
            		while (idxNum < 100)
            		{
            			var inputVal = "";
            			if(idxNum >= SysEnums.length ){
            				inputVal = "";
            			}else{
            				inputVal = SysEnums[idxNum].Lab;
            			}
            			SysEnumHtml = SysEnumHtml + "<tr>";
            			SysEnumHtml = SysEnumHtml + "<td class=\"Idx\" nowrap=\"\">"+idxNum+"</td>";
            			SysEnumHtml = SysEnumHtml + "<td><input id=\"TB_"+idxNum+"\" name=\"TB_"+idxNum+"\" type=\"text\" size=\"50\" value=\""+inputVal+"\"></td>";
            			SysEnumHtml = SysEnumHtml + "</tr>";
            			idxNum++;
            		}
            		$("#ListContent").html(SysEnumHtml);
                    return;
                }
            });

           
        });
        function Esc() {
            if (event.keyCode == 27)
                window.close();
            return true;
        }
        
        
    
    </script>
    <style type="text/css">
        .style1
        {
            width: 437px;
        }
        
    </style>
  </head>

  <body>
  <form id="frm">
	<table style="width:100%">
		<tr>
			<td valign="top">
				<table style="width:100%;">
					<caption>枚举属性</caption>
					<tr>
						<td nowarp=true >中文名:</td>
						<td ><input type="text" id="TB_Name" class="TB" name="TB_Name" onchange="TextBox1_TextChanged()"/></td>
					</tr>
					<tr>
						<td nowarp=true >编号:</td>
						<td><input type="text" id="TB_No" name="TB_No"/></td>
					</tr>
					<tr>
						<td colspan="2">
							<input type="button" id="Btn_Save" value="保存" onclick="Btn_Save_Click()" /> 
							<input type="button" id="Btn_SaveAndClose" value="保存&关闭" onclick="Btn_SaveAndClose_Click()" /> 
							<input type="button" id="Btn_SaveAndAddFrm" value="保存并放到表单里"  onclick="Btn_SaveAndAddFrm_Click()" /> 
							<input type="button" id="Btn_Del" value="删除" onclick="Btn_Del_Click()" /> 
						</td>
					</tr>
				</table>
			</td>
			<td valign="top" style="width:70%;">
				 <table width="100%">
				 	<caption id="caption"></caption>
				 	<div id="ListHead">
				 		<tr>
				 			<th>枚举值</th>
				 			<th>标签</th>
				 		</tr>
				 	</div>
				 	<tbody id="ListContent">
				 	</tbody>
				 </table>
			</td>
		</tr>
	</table>
	
	 <script type="text/javascript" language="javascript" >
        function Btn_Save_Click() {
        	var enumkey = GetQueryString("EnumKey");
        	var frmData = $("#frm").serialize();
        	$.ajax({
        		data: frmData,
                type: 'post',
                async: true,
                url: Handler + "?DoType=SysEnum_Save&EnumKey="+enumkey,
                dataType: 'html',
                success: function (json) {
                	/* json = JSON.parse(json);
                	alert(json.msg);
                    return; */
                	alert(json);
                },
                error: function (data) {
                    alert(data);
                    // console.info(data);
                }
            });
        }
        function Btn_SaveAndAddFrm_Click() {
      
        	var fk_mapdata = GetQueryString("FK_MapData");
            var KeyOfEn = GetQueryString("KeyOfEn");
            var idx = GetQueryString("IDX");
            var enumkey = GetQueryString("EnumKey");
        	var frmData = $("#frm").serialize();
    
        	$.ajax({
        		data: frmData,
                type: 'post',
                async: true,
                url: Handler + "?DoType=SysEnum_Save&EnumKey="+enumkey,
                dataType: 'html',
                success: function (json) {
                	/* json = JSON.parse(json);
                	if(json.isok == "true"){
                		alert(json.msg);
                	}
                	//local.href="EditEnum.aspx?DoType=New&FK_MapData="+fk_mapdata+"&EnumKey="+enumkey+"&GroupField=";
                    return; */
					alert(data);
                },
                error: function (data) {
                    alert(data);
                    // console.info(data);
                }
            });
        }
        
        function Btn_Del_Click() {
            
            var enumkey = GetQueryString("EnumKey");
        	var frmData = $("#frm").serialize();
        	$.ajax({
        		data: frmData,
                type: 'post',
                async: true,
                url: Handler + "?DoType=SysEnum_Del&EnumKey="+enumkey,
                dataType: 'html',
                success: function (json) {
                	/* json = JSON.parse(json);
                	if(json.isok == "true"){
                		alert(json.msg);
                	}
                    return; */
					alert(json);
                },
                error: function (data) {
                    alert(data);
                    // console.info(data);
                }
            });
        }
        
        
		function Btn_SaveAndClose_Click() {
            
            var enumkey = GetQueryString("EnumKey");
        	var frmData = $("#frm").serialize();
        	$.ajax({
        		data: frmData,
                type: 'post',
                async: true,
                url: Handler + "?DoType=SysEnum_Save&EnumKey="+enumkey,
                dataType: 'html',
                success: function (json) {
                	/* json = JSON.parse(json);
                	if(json.isok == "true"){
                		alert(json.msg);
                		window.close();
                	}
                    return; */
					alert(json);
					if (parent && parent.parent && typeof parent.parent.doCloseDialog === 'function') {
						parent.parent.doCloseDialog.call();
					} else {
						window.close();
					}
                },
                error: function (data) {
                    alert(data);
                    // console.info(data);
                }
            });
        }
    </script>
	</form>
</body>
</html>
